﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="clr-namespace:CAION2.Controls"
                    xmlns:prim="clr-namespace:Xceed.Wpf.Toolkit.Primitives;assembly=Xceed.Wpf.Toolkit"
                    xmlns:resources="clr-namespace:CAION2.Properties"
                    xmlns:themes="clr-namespace:Xceed.Wpf.Toolkit.Themes;assembly=Xceed.Wpf.Toolkit"
                    xmlns:xctk="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit">

    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />

    <Style x:Key="{x:Type controls:SearchTextBox}" TargetType="{x:Type controls:SearchTextBox}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Foreground" Value="{DynamicResource InputText}" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="BorderBrush" Value="{DynamicResource InputBorder}" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="LabelText" Value="{x:Static resources:Resources.RR_SearchText}" />
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="CaretBrush" Value="{DynamicResource InputText}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:SearchTextBox}">
                    <Border x:Name="ErrorBorder"
                            BorderBrush="Red"
                            BorderThickness="{Binding RelativeSource={RelativeSource TemplatedParent},
                                                      Path=BorderThickness}">
                        <Border x:Name="border"
                                Background="{DynamicResource InputBackground}"
                                BorderBrush="{DynamicResource InputBorder}"
                                BorderThickness="1">
                            <Grid x:Name="LayoutGrid">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ActualHeight}" />
                                </Grid.ColumnDefinitions>
                                <ScrollViewer x:Name="PART_ContentHost"
                                              Grid.Column="0"
                                              Margin="1"
                                              VerticalAlignment="Center" />
                                <Label x:Name="LabelText"
                                       Grid.Column="0"
                                       Margin="2"
                                       Content="{Binding RelativeSource={RelativeSource TemplatedParent},
                                                         Path=LabelText}"
                                       Foreground="{DynamicResource InputTextDisabled}"
                                       Padding="2,0,0,0" />
                                <Border x:Name="PART_SearchIconBorder"
                                        Grid.Column="1"
                                        HorizontalAlignment="Stretch"
                                        VerticalAlignment="Stretch"
                                        Background="Transparent"
                                        BorderThickness="0">
                                    <Path x:Name="SearchIcon"
                                          Width="12"
                                          Height="12"
                                          HorizontalAlignment="Center"
                                          VerticalAlignment="Center"
                                          Data="{StaticResource SearchIcon}"
                                          Fill="{DynamicResource InputText}"
                                          RenderTransformOrigin="0.5,0.5"
                                          Stretch="Uniform" />
                                </Border>
                            </Grid>
                        </Border>
                    </Border>
                    <ControlTemplate.Triggers>

                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="border" Property="Background" Value="{DynamicResource InputBackgroundHover}" />
                            <Setter TargetName="LabelText" Property="Foreground" Value="{DynamicResource InputTextHover}" />
                        </Trigger>

                        <Trigger Property="IsKeyboardFocusWithin" Value="True">
                            <Setter Property="BorderBrush" Value="{DynamicResource InputBorderHover}" />
                        </Trigger>

                        <Trigger Property="IsFocused" Value="True">
                            <Setter TargetName="LabelText" Property="Visibility" Value="Hidden" />
                        </Trigger>

                        <Trigger Property="HasText" Value="True">
                            <Setter TargetName="LabelText" Property="Visibility" Value="Hidden" />
                        </Trigger>

                        <Trigger SourceName="PART_SearchIconBorder" Property="IsMouseOver" Value="True">
                            <Setter TargetName="PART_SearchIconBorder" Property="Background" Value="{DynamicResource ButtonBackgroundHover}" />
                            <Setter TargetName="SearchIcon" Property="Fill" Value="{DynamicResource ButtonTextHover}" />
                        </Trigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="HasText" Value="True" />
                                <Condition Property="SearchMode" Value="Instant" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="SearchIcon" Property="Data" Value="{StaticResource ClearIcon}" />
                        </MultiTrigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="PART_SearchIconBorder" Property="IsMouseOver" Value="True" />
                                <Condition Property="HasText" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_SearchIconBorder" Property="Background" Value="{DynamicResource ButtonBackgroundHover}" />
                        </MultiTrigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="PART_SearchIconBorder" Property="IsMouseOver" Value="True" />
                                <Condition Property="IsMouseLeftButtonDown" Value="True" />
                                <!--
                                    <Condition Property="HasText"
                                    Value="True" />
                                -->
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_SearchIconBorder" Property="Background" Value="{DynamicResource ButtonBackgroundPressed}" />
                            <Setter TargetName="SearchIcon" Property="Fill" Value="{DynamicResource ButtonTextPressed}" />
                        </MultiTrigger>

                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="NumericUpDown" TargetType="{x:Type prim:InputBase}">
        <Setter Property="Background" Value="{DynamicResource InputBackground}" />
        <Setter Property="Foreground" Value="{DynamicResource InputText}" />
        <Setter Property="BorderBrush" Value="{DynamicResource InputBorder}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="TextAlignment" Value="Right" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Control">
                    <xctk:ButtonSpinner x:Name="PART_Spinner"
                                        AllowSpin="{Binding AllowSpin,
                                                            RelativeSource={RelativeSource TemplatedParent}}"
                                        Background="{TemplateBinding Background}"
                                        BorderBrush="{TemplateBinding BorderBrush}"
                                        BorderThickness="{TemplateBinding BorderThickness}"
                                        IsTabStop="False"
                                        ShowButtonSpinner="{Binding ShowButtonSpinner,
                                                                    RelativeSource={RelativeSource TemplatedParent}}">
                        <xctk:WatermarkTextBox x:Name="PART_TextBox"
                                               MinWidth="20"
                                               HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                               VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                               AcceptsReturn="False"
                                               Background="{TemplateBinding Background}"
                                               BorderThickness="0"
                                               ContextMenu="{TemplateBinding ContextMenu}"
                                               FontFamily="{TemplateBinding FontFamily}"
                                               FontSize="{TemplateBinding FontSize}"
                                               FontStretch="{TemplateBinding FontStretch}"
                                               FontStyle="{TemplateBinding FontStyle}"
                                               FontWeight="{TemplateBinding FontWeight}"
                                               Foreground="{TemplateBinding Foreground}"
                                               IsReadOnly="{Binding IsReadOnly,
                                                                    RelativeSource={RelativeSource TemplatedParent}}"
                                               Padding="{TemplateBinding Padding}"
                                               SelectAllOnGotFocus="{Binding SelectAllOnGotFocus,
                                                                             RelativeSource={RelativeSource TemplatedParent}}"
                                               TabIndex="{TemplateBinding TabIndex}"
                                               TextAlignment="{Binding TextAlignment,
                                                                       RelativeSource={RelativeSource TemplatedParent}}"
                                               TextWrapping="NoWrap" />
                    </xctk:ButtonSpinner>

                    <ControlTemplate.Triggers>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsEnabled" Value="True" />
                                <Condition Property="IsMouseOver" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter Property="Background" Value="{DynamicResource InputBackgroundHover}" />
                            <Setter Property="Foreground" Value="{DynamicResource InputTextHover}" />
                        </MultiTrigger>
                        <Trigger Property="IsKeyboardFocusWithin" Value="True">
                            <Setter Property="BorderBrush" Value="{DynamicResource Accent}" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Foreground" Value="{DynamicResource InputTextDisabled}" />
                        </Trigger>
                        <Trigger Property="IsFocused" Value="True">
                            <Setter Property="BorderBrush" Value="{DynamicResource Accent}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style BasedOn="{StaticResource NumericUpDown}" TargetType="{x:Type xctk:IntegerUpDown}" />

    <Geometry x:Key="UpArrowGeometry">M 0,3 C0,3 0,4 0,4 0,4 3,4 3,4 3,4 3,3 3,3 3,3 4,3 4,3 4,3 4,4 4,4 4,4 7,4 7,4 7,4 7,3 7,3 7,3 6,3 6,3 6,3 6,2 6,2 6,2 5,2 5,2 5,2 5,1 5,1 5,1 4,1 4,1 4,1 4,0 4,0 4,0 3,0 3,0 3,0 3,1 3,1 3,1 2,1 2,1 2,1 2,2 2,2 2,2 1,2 1,2 1,2 1,3 1,3 1,3 0,3 0,3 z</Geometry>
    <Geometry x:Key="DownArrowGeometry">M 0,1 C0,1 0,0 0,0 0,0 3,0 3,0 3,0 3,1 3,1 3,1 4,1 4,1 4,1 4,0 4,0 4,0 7,0 7,0 7,0 7,1 7,1 7,1 6,1 6,1 6,1 6,2 6,2 6,2 5,2 5,2 5,2 5,3 5,3 5,3 4,3 4,3 4,3 4,4 4,4 4,4 3,4 3,4 3,4 3,3 3,3 3,3 2,3 2,3 2,3 2,2 2,2 2,2 1,2 1,2 1,2 1,1 1,1 1,1 0,1 0,1 z</Geometry>

    <DataTemplate x:Key="IncreaseGlyphNormalKey">
        <Path Width="7"
              Height="4"
              HorizontalAlignment="Center"
              VerticalAlignment="Center"
              Data="{StaticResource UpArrowGeometry}"
              Fill="{DynamicResource ButtonText}"
              Focusable="False"
              SnapsToDevicePixels="True" />
    </DataTemplate>

    <DataTemplate x:Key="IncreaseGlyphDisabledKey">
        <Path Width="7"
              Height="4"
              HorizontalAlignment="Center"
              VerticalAlignment="Center"
              Data="{StaticResource UpArrowGeometry}"
              Fill="{DynamicResource InputTextDisabled}"
              Focusable="False"
              SnapsToDevicePixels="True" />
    </DataTemplate>

    <DataTemplate x:Key="DecreaseGlyphNormalKey">
        <Path Width="7"
              Height="4"
              HorizontalAlignment="Center"
              VerticalAlignment="Center"
              Data="{StaticResource DownArrowGeometry}"
              Fill="{DynamicResource ButtonText}"
              Focusable="False"
              SnapsToDevicePixels="True" />
    </DataTemplate>

    <DataTemplate x:Key="DecreaseGlyphDisabledKey">
        <Path Width="7"
              Height="4"
              HorizontalAlignment="Center"
              VerticalAlignment="Center"
              Data="{StaticResource DownArrowGeometry}"
              Fill="{DynamicResource InputTextDisabled}"
              Focusable="False"
              SnapsToDevicePixels="True" />
    </DataTemplate>

    <Style x:Key="SpinnerButtonStyleKey" TargetType="RepeatButton">
        <Setter Property="Background" Value="{DynamicResource ButtonBackground}" />
        <Setter Property="BorderBrush" Value="{DynamicResource ButtonBorder}" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Padding" Value="2,2" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="RepeatButton">
                    <Grid>
                        <Button x:Name="Chrome"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                SnapsToDevicePixels="true" />

                        <ContentPresenter Margin="{TemplateBinding Padding}"
                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource ButtonTextDisabled}" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="{DynamicResource ButtonBackgroundHover}" />
                            <Setter Property="Foreground" Value="{DynamicResource ButtonTextHover}" />
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter Property="Background" Value="{DynamicResource ButtonBackgroundPressed}" />
                            <Setter Property="Foreground" Value="{DynamicResource ButtonTextPressed}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type xctk:ButtonSpinner}">
        <Setter Property="Background" Value="{DynamicResource ButtonBackground}" />
        <Setter Property="Foreground" Value="{DynamicResource ButtonText}" />
        <Setter Property="BorderBrush" Value="{DynamicResource ButtonBorder}" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Focusable" Value="False" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="IsTabStop" Value="True" />
        <Setter Property="Padding" Value="0" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type xctk:ButtonSpinner}">
                    <Border x:Name="Border"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            SnapsToDevicePixels="True">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <ContentPresenter Margin="{TemplateBinding Padding}"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                              Focusable="False"
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />

                            <Grid Grid.Column="1"
                                  Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"
                                  Visibility="{TemplateBinding ShowButtonSpinner,
                                                               Converter={StaticResource BooleanToVisibilityConverter}}">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>

                                <RepeatButton x:Name="PART_IncreaseButton"
                                              ContentTemplate="{StaticResource IncreaseGlyphNormalKey}"
                                              IsTabStop="{TemplateBinding IsTabStop}"
                                              Style="{StaticResource SpinnerButtonStyleKey}" />

                                <RepeatButton x:Name="PART_DecreaseButton"
                                              Grid.Row="1"
                                              ContentTemplate="{StaticResource DecreaseGlyphNormalKey}"
                                              IsTabStop="{TemplateBinding IsTabStop}"
                                              Style="{StaticResource SpinnerButtonStyleKey}" />

                            </Grid>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="{DynamicResource ButtonBackgroundHover}" />
                            <Setter Property="Foreground" Value="{DynamicResource ButtonTextHover}" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Foreground" Value="{DynamicResource ButtonTextDisabled}" />
                        </Trigger>
                        <Trigger SourceName="PART_IncreaseButton" Property="IsEnabled" Value="False">
                            <Setter TargetName="PART_IncreaseButton" Property="ContentTemplate" Value="{StaticResource IncreaseGlyphDisabledKey}" />
                        </Trigger>
                        <Trigger SourceName="PART_DecreaseButton" Property="IsEnabled" Value="False">
                            <Setter TargetName="PART_DecreaseButton" Property="ContentTemplate" Value="{StaticResource DecreaseGlyphDisabledKey}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>